package com.zline.foodraise.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.photoselector.model.PhotoModel;
import com.zline.foodraise.listener.RecyclerItemClicked;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/8/24.
 * 带删除功能的图片
 */
@EViewGroup(resName = "removable_photo_item")
public class RemovedPhotoItem extends RelativeLayout {
    private static final String LOG_TAG = NewPhotoItem.class.getSimpleName();
    @ViewById(resName = "remove_photo_iv")
    ImageView photo_iv;
    @ViewById(resName = "remove_photo_icon_iv")
    ImageView rm_iv;
    int position;
    PhotoModel photoModel;
    RecyclerItemClicked itemClicked;
    public RemovedPhotoItem(Context context) {
        super(context);
    }

    public void bind(PhotoModel photoModel, int position) {
        this.position = position;
        this.photoModel=photoModel;
        setImageDrawable(photoModel);
    }

    /**
     * 设置路径下的图片对应的缩略图
     */
    public void setImageDrawable(PhotoModel photo) {
        DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
                .showImageOnLoading(com.photoselector.R.mipmap.ic_picture_loading)
                .showImageOnFail(com.photoselector.R.mipmap.ic_picture_loadfailed)
                .cacheInMemory(true).cacheOnDisk(true)
                .resetViewBeforeLoading(true).considerExifParams(false)
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoader.getInstance().displayImage(
                "file://" + photo.getOriginalPath(), photo_iv, imageOptions);
    }

    public void setRecycleItemClickListener(RecyclerItemClicked itemClickListener){
        this.itemClicked=itemClickListener;
    }

    @Click(resName = "remove_photo_icon_iv")
    void onClick(){
        itemClicked.onRecyclerClickedDelete(position);
    }

}
